package com.antlr;


import com.gen.ExprLexer;
import com.gen.ExprParser;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CodePointCharStream;
import org.antlr.v4.runtime.CommonTokenStream;


import java.util.Arrays;
import java.util.List;
import java.util.Objects;

public class ExprDemo {

    public static void main(String[] args) {

        List<String> testSet = Arrays.asList(
                "1+2",
                "1+2+3*4",
                "3/3",
                "10/2",
                "5*5+10+5*5"
        );

        List<Integer> res = Arrays.asList(
            3,15,1,5,60
        );
        EvalExprVisitor evalExprVisitor = new EvalExprVisitor();
        for (int i = 0; i < testSet.size(); i++) {
            evalExprVisitor.visitRoot(testSet.get(i));
            System.out.println(
                    testSet.get(i)
                    +"的结果为："
                    +EvalExprVisitor.result
                    + "，结果"+(EvalExprVisitor.result==(res.get(i))?"正确":"错误")
            );
        }
    }

}
